from router import Router
from dto import Envelope
import json
PASSWD = 'CISCO'
class Container:
    
    # 路由器映射map
    _router_map = {}

    _all_output = ''

    # 将字符串处理为json
    def to_json(self, st):
        e = Envelope(st)
        return str(e)
    # 初始化
    def __init__(self):
        self._router_map['R0'] = Router('172.16.0.2',PASSWD)
        self._router_map['R1'] = Router('172.16.0.3',PASSWD)
        self._router_map['R2'] = Router('172.16.0.4',PASSWD)

    # 获取全部输出
    def all_output(self):
        return self.to_json(self._all_output);

    # 初始化拓扑
    def init_topology(self, r_id):
        res = self._router_map[r_id].init_topology(r_id)
        self._all_output += res;
        return self.to_json(res);

    # 配置acl
    def config_acl(self, r_id):
        res = self._router_map[r_id].config_acl(r_id);
        self._all_output += res;
        return self.to_json(res);

    # 取消配置acl
    def no_config_acl(self, r_id):
        res = self._router_map[r_id].no_config_acl(r_id);
        self._all_output += res;
        return self.to_json(res);

    # 检验acl
    def check_acl(self, r_id):
        res = self._router_map[r_id].check_acl(r_id);
        self._all_output += res;
        return self.to_json(res);
    

    # def init(self):
    #     self._router_map[rId].execute_cmd('')
if __name__ == '__main__':
    pass
